﻿using BLL;
using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Dryricenet
{
    public partial class ph_Uppwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = Session["Name"].ToString();
            string pwd = Session["Pwd"].ToString();
            string qrPwd = "";
            if (pwdQ.Text.Trim() != "" && pwdX.Text.Trim() != "" && pwdY.Text.Trim() != "")
            {
                if (pwdY.Text.Trim() != pwd)
                {
                    Response.Write("<script>javascript:alert('原密码不正确');history.back();</script>");
                }
                else if (pwdY.Text.Trim() == pwdX.Text.Trim())
                {
                    Response.Write("<script>javascript:alert('新密码与原密码不能相同！');history.back();</script>");
                }
                else if (pwdQ.Text.Trim() != pwdX.Text.Trim())
                {

                    Response.Write("<script>javascript:alert('确认新密码与新密码不相同！');history.back();</script>");
                }
                else if (pwdQ.Text.Trim() == pwdX.Text.Trim())
                {
                    qrPwd = pwdQ.Text.Trim();
                    if (userBLL.updatePwd(name, qrPwd))
                    {
                        System.Data.DataTable dt = userBLL.selectNameBll(name);
                        DataRow dr = dt.Rows[0];//第一条数据
                        int userID = Convert.ToInt32(dr["UserID"].ToString());
                        Log l = new Log();
                        l.OperTime = DateTime.Now;
                        l.OperPerson = name;
                        l.Type = "添加用户";
                        l.State = "添加成功";
                        l.ComputerName = Dns.GetHostName().ToUpperInvariant();
                        l.System = Systems.GetOSNameByUserAgent(Environment.OSVersion.ToString());
                        l.UserID = userID;
                        LogBLL.LogAddBLL(l);
                        Response.Write("<script>alert('修改成功！');</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('修改失败！');</script>");
                    }

                }
            }
            else
            {
                Response.Write("<script>javascript:alert('请填写完整！');</script>");
            }
        }
    }
}